﻿@{
    ViewBag.Title = "Associar Usuários a Papel";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
<fieldset>
    <legend></legend>
    <table>
        <tr>
            <td style="vertical-align: top;">
                <div class="editor-label">
                    <label>
                        Papel:</label>
                </div>
                <div class="editor-field">
                    @Html.ListBox("PapelID")
                </div>
            </td>
            <td style="padding-left: 30px">
                <div id="divLoginUsuario" style="display: none">
                    <div class="editor-label">
                        <label>
                            Login:</label>
                    </div>
                    <div class="editor-field">
                        <input type="text" id="txtLogin" style="width: 150px" />
                        <button type="button" class="btn btn-small btn-primary" style="margin-bottom: 9px"
                            id="btnAdicionar">
                            Adicionar
                        </button>
                    </div>
                    <div id="divMensagem">
                    </div>
                </div>
                <div id="divUsuarios">
                </div>
            </td>
        </tr>
    </table>
</fieldset>
<script type="text/javascript">
    $(function () {
        $("#PapelID").change(function () {
            $('#divUsuarios').load("/Papel/ListarUsuarios", { papelID: this.value });
            $('#divLoginUsuario').show();
        });

        $("#btnAdicionar").click(function () {
            $('#divMensagem').load("/Papel/AdicionarUsuario", { loginUsuario: $("#txtLogin").val(), papelID: $("#PapelID").find(':selected').val() }, function () {
                $('#divUsuarios').html('');
                $('#divUsuarios').load("/Papel/ListarUsuarios", { papelID: $("#PapelID").find(':selected').val() })
            });
        });


    });
</script>
